<html>
<head><meta charset="utf-8"><title>freevar refactoring #60205 · t-compiler/wg-rfc-2229 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/index.html">t-compiler/wg-rfc-2229</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html">freevar refactoring #60205</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="164015623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164015623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164015623">(Apr 23 2019 at 18:24)</a>:</h4>
<p>OK, well, <span class="user-mention" data-user-id="116773">@csmoe</span> I <a href="https://github.com/rust-lang/rust/blob/7b4f8f969caa9321b2c4881b00162ee2d68896fd/src/librustc_mir/hair/cx/expr.rs#L989" target="_blank" title="https://github.com/rust-lang/rust/blob/7b4f8f969caa9321b2c4881b00162ee2d68896fd/src/librustc_mir/hair/cx/expr.rs#L989">wrote up some mentoring instructions here</a> for one case. Let me know if that makes any sense to you. =) (And if you still have time.)</p>



<a name="164016441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164016441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164016441">(Apr 23 2019 at 18:32)</a>:</h4>
<p>the link is probably <a href="https://github.com/rust-lang/rust/issues/60205#issuecomment-485919357" target="_blank" title="https://github.com/rust-lang/rust/issues/60205#issuecomment-485919357">this</a> instead</p>



<a name="164017543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164017543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164017543">(Apr 23 2019 at 18:44)</a>:</h4>
<p>sigh</p>



<a name="164056290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164056290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164056290">(Apr 24 2019 at 05:58)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> WIP <a href="https://github.com/rust-lang/rust/pull/60227" target="_blank" title="https://github.com/rust-lang/rust/pull/60227">https://github.com/rust-lang/rust/pull/60227</a></p>



<a name="164058547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164058547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164058547">(Apr 24 2019 at 06:52)</a>:</h4>
<blockquote>
<p>the closure's node-id -- we can get that by calling <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/map/struct.Map.html#method.as_local_node_id" target="_blank" title="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/map/struct.Map.html#method.as_local_node_id">as_local_node_id</a> on the closure def-id (which the calling function already has)</p>
</blockquote>
<p><code>as_local_node_id</code> returns <code>Option&lt;NodeId&gt;</code>, so how to deal with <code>None</code>?</p>



<a name="164058908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164058908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ange <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164058908">(Apr 24 2019 at 07:00)</a>:</h4>
<p><span class="user-mention" data-user-id="116773">@csmoe</span> I think it would be an internal compiler error if that failed?</p>



<a name="164058933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164058933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164058933">(Apr 24 2019 at 07:01)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="116773">csmoe</span> I think it would be an internal compiler error if that failed?</p>
</blockquote>
<p>sounds reasonable <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="164184893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164184893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164184893">(Apr 25 2019 at 16:15)</a>:</h4>
<p>unwrap :)</p>



<a name="164184899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164184899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164184899">(Apr 25 2019 at 16:15)</a>:</h4>
<p>Well, it depends</p>



<a name="164184913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/164184913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#164184913">(Apr 25 2019 at 16:15)</a>:</h4>
<p>But yeah in this case I think unwrap is fine -- basically, the <code>None</code> indicates a def-id from some other crate, but we are only running this code on closures in the current crate</p>



<a name="165589197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/165589197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#165589197">(May 14 2019 at 03:15)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> sorry for the delay,  I was very busy in the past few days.<br>
As the master branch removed <code>with_freevars</code> and seemed already refactored to what we wanna . <a href="https://github.com/rust-lang/rust/blob/a9ec99f4201ec33026a468ef1289f98a95b4d71a/src/librustc_mir/hair/cx/expr.rs#L519" target="_blank" title="https://github.com/rust-lang/rust/blob/a9ec99f4201ec33026a468ef1289f98a95b4d71a/src/librustc_mir/hair/cx/expr.rs#L519">https://github.com/rust-lang/rust/blob/a9ec99f4201ec33026a468ef1289f98a95b4d71a/src/librustc_mir/hair/cx/expr.rs#L519</a><br>
so this issue should be marked done?</p>



<a name="165931816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/165931816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#165931816">(May 17 2019 at 20:01)</a>:</h4>
<p><span class="user-mention" data-user-id="116773">@csmoe</span> lol .. ok :)</p>



<a name="165931817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/165931817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#165931817">(May 17 2019 at 20:01)</a>:</h4>
<p>well,</p>



<a name="165931822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/165931822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#165931822">(May 17 2019 at 20:01)</a>:</h4>
<p>there are other locations, have you looked into those?</p>



<a name="165931832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/165931832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#165931832">(May 17 2019 at 20:02)</a>:</h4>
<p>actually, hmm</p>



<a name="165931887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/165931887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#165931887">(May 17 2019 at 20:02)</a>:</h4>
<p>so <code>tcx.upvars</code> is .. not necessarily what we want</p>



<a name="165931907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/165931907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#165931907">(May 17 2019 at 20:02)</a>:</h4>
<p>I think that's just a "nicer" version of <code>with_freevars</code> that <span class="user-mention" data-user-id="119009">@eddyb</span> introduced -- but what we really want is to be getting our information from the results of type check</p>



<a name="166080624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/166080624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#166080624">(May 20 2019 at 12:30)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> to bring you up to speed: I have an almost-done refactor that, in the end, will remove <code>Def::Upvar</code> and compute <code>tcx.upvars</code> from HIR (so that HIR lowering can do funky things with closures and <code>rustc_resolve</code> doesn't need to know about it)</p>



<a name="166080664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/166080664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#166080664">(May 20 2019 at 12:31)</a>:</h4>
<p>it's plausible that we could remove <code>tcx.upvars</code> completely, and rely on <code>TypeckTables</code>, as MC and EUV run during or after typeck, and should always have access to those tables</p>



<a name="166080864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/166080864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#166080864">(May 20 2019 at 12:34)</a>:</h4>
<p>note that right now, the <code>upvar_list</code> (which IMO should just be named <code>upvars</code>) in <code>TypeckTables</code> is not very different from <code>tcx.upvars</code> and therefore I will likely not switch uses of one to the other</p>



<a name="167227397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167227397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167227397">(Jun 03 2019 at 20:20)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> is this in a PR that's available to view?</p>



<a name="167227616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167227616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167227616">(Jun 03 2019 at 20:22)</a>:</h4>
<p>it's merged, lol</p>



<a name="167227665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167227665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167227665">(Jun 03 2019 at 20:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> enjoy <a href="https://github.com/rust-lang/rust/pull/61276" target="_blank" title="https://github.com/rust-lang/rust/pull/61276">https://github.com/rust-lang/rust/pull/61276</a></p>



<a name="167227696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167227696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167227696">(Jun 03 2019 at 20:23)</a>:</h4>
<p>thanks :)</p>



<a name="167227790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167227790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167227790">(Jun 03 2019 at 20:24)</a>:</h4>
<p>also, <a href="https://github.com/rust-lang/rust/pull/61413" target="_blank" title="https://github.com/rust-lang/rust/pull/61413">https://github.com/rust-lang/rust/pull/61413</a></p>



<a name="167227796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167227796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167227796">(Jun 03 2019 at 20:24)</a>:</h4>
<p>which is ready, huh</p>



<a name="167231805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167231805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167231805">(Jun 03 2019 at 21:02)</a>:</h4>
<p>I should probably try to revise the instructions here in light of that</p>



<a name="167486526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167486526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167486526">(Jun 06 2019 at 14:29)</a>:</h4>
<blockquote>
<p>I should probably try to revise the instructions here in light of that</p>
</blockquote>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> would you mind updating the instruction after the compiler meeting? I'm lost with the refactoring.</p>



<a name="167606424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/freevar%20refactoring%20%2360205/near/167606424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/freevar.20refactoring.20.2360205.html#167606424">(Jun 07 2019 at 19:32)</a>:</h4>
<p>yeah I will try to do so! might take a bit though</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>